import { reactive, onMounted } from 'vue';
import axios from 'axios';

export default function() {
  // 数据
  let dogList = reactive([])

  // 方法
  async function getDog() {
    try {
      let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
      dogList.push(result.data.message)
    } catch(error) {
      console.log(error)
      alert(error)
    }
  }

  onMounted(() => getDog())

  // 向外部提供
  return {dogList, getDog}
}